package org.example.hiveJsonParser;

import org.apache.hadoop.hive.ql.exec.UDF;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

/*工作日0 休息日1 法定假日2*/
public class HolidayParser extends UDF {
    String[] strArr = {"2020-01-01","2020-01-24","2020-01-25","2020-01-26","2020-01-27","2020-01-28","2020-01-29",
            "2020-01-30","2020-04-04","2020-04-05","2020-04-06","2020-05-01","2020-05-02","2020-05-03","2020-05-04",
            "2020-05-05","2020-06-25","2020-06-26","2020-06-27","2020-10-01","2020-10-02","2020-10-03","2020-10-04"
            ,"2020-10-05","2020-10-06","2020-10-07","2020-10-08"};
    String[] strArr2 = {"2020-01-19","2020-02-01","2020-04-26","2020-05-09","2020-06-28","2020-09-27","2020-10-10"
    };
    List<String> L_holiday = Arrays.asList(strArr);
    List<String> L_workday = Arrays.asList(strArr2);

    public Integer evaluate(String time) {
        if (L_holiday.contains(time)) return 2;
        if (L_workday.contains(time)) return 0;
        int dayOfWeek = LocalDate.parse(time).getDayOfWeek().getValue(); // 1 monday 7 sunday
        return dayOfWeek>=6?1:0;
    }
}
